import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app'
import menu from './modules/menu'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {},
  mutations: {
    // epin 的
    SETEPINCONFIG(state, { key, config }) {
      console.log(state, key, config)
      state.app.epinConfig[key] = config
      state.app.epinConfig = Object.assign({}, state.app.epinConfig)
    }
  },
  actions: {
    setAuthMenu() {},
    logout({ dispatch, commit }) {
      dispatch('app/logout', { root: true })
    },
    // 兼容老chunk
    setToken({ dispatch, commit }, token) {
      commit('app/SETAUTHORIZATION', token, { root: true })
    }
  },
  getters: {
    // 建议将 getters 等 加在各自模块中，有namespqce
    // 这边的根getters是为了兼容老架子的 chunk
    getToken: state => state.app.authorization,
    getLoginId: state => state.app.userMainInfo.loginId,
    getUsername: state => state.app.userMainInfo.username,
    getOrgName: state => state.app.userMainInfo.orgName,
    getOrgCode: state => state.app.userMainInfo.orgCode,
    getRoles: state => state.app.userMainInfo.roles,
    getEditBtnShow: state => state.app.userMainInfo.editBtnShow,
    getUserType: state => state.app.userMainInfo.type,
    getUserMobile: state => state.app.userMainInfo.mobile,
    getUserEmail: state => state.app.userMainInfo.email
    // 建议将 getters 等 加在各自模块中，有namespqce
    // 这边的根getters是为了兼容老架子的 chunk
  },
  modules: {
    app,
    menu
  }
})
